/**
 * @class UI-提示行
 * @author DuskyHuang 圣子
*/

import { _decorator, Component, Animation, Label, Widget, UITransform } from 'cc';
const { ccclass, requireComponent, property } = _decorator;

@ccclass('cocosmos.TipLine')
@requireComponent(Animation)
export class TipLine extends Component {

    @property(Label) public show: Label;
    @property(Label) public hide: Label;

    public set string(content: string) {
        const uit = this.getComponent(UITransform)
        uit.setContentSize(String.Length(content) * this._cw * 0.5, uit.height);
        this.getComponent(Widget)?.updateAlignment();
        this.hide.string = this.show.string;
        this.show.string = content;
        this._anim.play();
    }

    protected onLoad(): void {
        this._anim = this.getComponent(Animation);
        this._cw = this.show.fontSize;
    }

    private _anim: Animation;
    private _cw: num.px;
}